﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using ConsolidationTool.Common;
using System.Web.UI.WebControls;
using ConsolidationTool.WebParts.ControlTemplates;

namespace ConsolidationTool.WebParts.Layouts.ConsolidationTool.WebParts
{
    public partial class FixPromission : FSReportBase
    {

        public override void BeforLoad()
        {
            Button1.Click += new EventHandler(Button1_Click);

            if (!IsPostBack)
            {
                BindCheckList();
            }

            base.BeforLoad(); 
            TopSelector.monthTextBox.Visible = false;
        }

        public override CommonEntitySelector TopSelector
        {
            get
            {
                return commonEntitySelector as ControlTemplates.CommonEntitySelector;
            }
        }


        private void BindCheckList()
        {
            SPWeb web = SPContext.Current.Web;
            int listCount = web.Lists.Count;
            for (int i = 0; i < listCount; i++)
            {
                SPList list = web.Lists[i];
                var s = list.Fields.TryGetFieldByStaticName("CoCd");
                if (s != null)
                    CheckBoxList1.Items.Add(list.Title);
            }
        }

        void Button1_Click(object sender, EventArgs e)
        {
            string json=@"
       { title: 'Misc.', identity: 'BS02010403-5', group: 'Table1', fields: [
         { from: [{ method: 'N_1_CM'}] },
        { from: [{ method: 'CM'}] },
        { emptycolumn: true },
        { list: 'R_Budget_Inventory', from: [{ identity: 'BS03010403-5', field: 'Dec', method: 'CM'}] },
        { emptycolumn: true },
        { equ: '({0})/12',from: [{  method: 'R12'}] },
        { emptycolumn: true },
        { from: [{ identity: 'BS02010406-5', method: 'CM'}] },
        { from: [{ identity: 'BS02010407-5', method: 'CM'}] }
]
}
";
            MappingLocator ML = new MappingLocator(CEntity);

             

            return;
            using (SPSite s = new SPSite(SPContext.Current.Site.ID))
            {
                SPWeb web = s.OpenWeb();

                int ccount = CheckBoxList1.Items.Count;
                for (int c = 0; c < ccount; c++)
                {
                    var citem = CheckBoxList1.Items[c];
                    if (citem.Selected)
                    {
                        SPList l = web.Lists[citem.Text];
                        int itemcount = l.Items.Count;
                        for (int i = 0; i < itemcount; i++)
                        {
                            SPListItem item = l.Items[i];
                            Guid MywebGuid = web.ID;
                            Guid MysiteGuid = s.ID;

                            var SelectedEntity = BusinessService.getEntity(item["CoCd"] + "");

                            Guid listID = item.ParentList.ID;
                            int listItemID = item.ID;

                            Utilities.UserRoleAssignment(MysiteGuid, MywebGuid, listID, listItemID, SelectedEntity, SPRoleType.WebDesigner);

                        }
                    }
                }
            }

        }
    }
}
